import { defineStore } from "pinia";
import { getFound } from "@/api/found";


type state = {
    DataList:listType[],
    count:number,
    flag:boolean,
    inputs:string
}
export const usefounded = defineStore(
    'founded',
    {
        state:():state=>{
            return {
                DataList:[],
                count:0,
                flag:false,
                inputs:''
            }
        },
        getters:{},
        actions:{
            async fetchData(){
                this.count++;
                let res = await getFound(this.inputs,this.count,10);
                if(!res.data){
                    this.flag = true;
                    return
                }else if(res.data<10){
                    this.flag = true;
                }
                this.DataList = [...this.DataList,...res.data]
                

            },
            changeKey(v:string){
                this.inputs = v;
            },
            removes(){
                this.DataList = [];
                this.count = 0;
                this.flag = false;
            }
        }
    }
)